package com.zhenyi.jiahua.index.admin;

import java.util.List;

import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.SqlPara;
import com.jiahua.common.model.JhStaff;
import com.zhenyi.jiahua.index.JHController;

public class FollowController extends JHController {

	/**
	 * 跟进列表
	 */
	@Override
	public void list() {

		Integer[] types = { JhStaff.TYPE_TMK, JhStaff.TYPE_TUIGUANG };
		List<JhStaff> staffs = JhStaff.dao.findByTypes(types);
		setAttr("staffs", jsonObject(staffs));

		String startDate = getStartToday();
		String endDate = getEndToday();
		Kv kv = Kv.create();
		kv.set("startTime", startDate);
		kv.set("endTime", endDate);
		Long staffId = getParaToLong("staffId");
		if (staffId != null) {
			kv.set("staffId", staffId);
			setAttr("staffId", staffId);
		}
		SqlPara sqlPara = Db.use("jiahua").getSqlPara("JHFollow", kv);
		Page<Record> pages = Db.use("jiahua").paginate(getPage(), PAGE_SIZE, sqlPara);
		setRainbow(pages);
		setItems(jsonObject(pages.getList()));
		setAttr("startDate", startDate);
		setAttr("endDate", endDate);
		render("/jh/admin/follow/list.html");
	}

	/**
	 * 我的跟进
	 */
	@Override
	public void index() {
		String startDate = getStartToday();
		String endDate = getEndToday();
		Kv kv = Kv.create();
		kv.set("startTime", startDate);
		kv.set("endTime", endDate);
		JhStaff staff = getStaff();
		Long staffId = staff.getId();
		if (staffId != null) {
			kv.set("staffId", staffId);
		}
		SqlPara sqlPara = Db.use("jiahua").getSqlPara("JHFollow", kv);
		Page<Record> pages = Db.use("jiahua").paginate(getPage(), PAGE_SIZE, sqlPara);
		setRainbow(pages);
		setItems(jsonObject(pages.getList()));
		setAttr("startDate", startDate);
		setAttr("endDate", endDate);
		render("/jh/admin/follow/index.html");
	}

}
